package com.zjdiepu.www.manage.api.base;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.text.DecimalFormat;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.base.core.PageVo;
import com.zjdiepu.www.base.enums.type.DataDicType;
import com.zjdiepu.www.common.util.CollectionInitUtil;
import com.zjdiepu.www.ibiz.cache.ICachedDictionaryService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessService;
import com.zjdiepu.www.ibiz.zx.IZxQueryCreditApplySubService;
import com.zjdiepu.www.model.base.ext.ClientTypeExt;
import com.zjdiepu.www.model.base.vo.BusinessTotalVo;
@RestController
@RequestMapping(value= "InsideCountController", produces="application/json;charset=UTF-8")
@Api(tags = {""}, produces="application/json;charset=UTF-8")
public class InsideCountController extends BaseController{

	@Resource
	private IYwBusinessService ywBusinessService;
	@Resource
	private IZxQueryCreditApplySubService zxQueryCreditApplySubService;
	@Resource
	private ICachedDictionaryService cachedDictionaryService;
	
	@ApiOperation(value = "订单数量统计", response = Boolean.class, httpMethod="POST", tags={"新增"})
    @RequestMapping(value = "countBusinessNum", method = RequestMethod.POST)
	public ApiResponse countBusinessNum(@ModelAttribute ClientTypeExt clientTypeExt){
		clientTypeExt.notDeleted();
        PageVo page = getPage(clientTypeExt);
		int records=ywBusinessService.countBusinessNum(clientTypeExt);
		if (records > 0) {
			page.setRecords(records);
			int num=ywBusinessService.countAllBusinessNum(clientTypeExt);
            List<BusinessTotalVo> dpBaseDataDictionaries = ywBusinessService.selectBusinessNum(clientTypeExt);
            for (BusinessTotalVo businessTotalVo : dpBaseDataDictionaries) {
            	businessTotalVo.setPercent(Double.parseDouble(new DecimalFormat("0.00").format((float)businessTotalVo.getBusinessTotal()*100/num)));
			}
            page.setRows(dpBaseDataDictionaries);
        } else {
            page.setRows(CollectionInitUtil.emptyList());
        }
		
		return ApiResponse.success(page);
	}
	
	@ApiOperation(value = "征信查询申请统计", response = Boolean.class, httpMethod="POST", tags={"新增"})
    @RequestMapping(value = "countZXNum", method = RequestMethod.POST)
	public ApiResponse countZXNum(@ModelAttribute ClientTypeExt clientTypeExt){
		clientTypeExt.notDeleted();
        PageVo page = getPage(clientTypeExt);
		int records=zxQueryCreditApplySubService.countZXNum(clientTypeExt);
		if (records > 0) {
			page.setRecords(records);
			int num=zxQueryCreditApplySubService.countAllZXNum(clientTypeExt);
            List<BusinessTotalVo> dpBaseDataDictionaries = zxQueryCreditApplySubService.selectZXNum(clientTypeExt);
            for (BusinessTotalVo businessTotalVo : dpBaseDataDictionaries) {
            	businessTotalVo.setPercent(Double.parseDouble(new DecimalFormat("0.00").format((float)businessTotalVo.getBusinessTotal()*100/num)));
			}
            page.setRows(dpBaseDataDictionaries);
        } else {
            page.setRows(CollectionInitUtil.emptyList());
        }
		
		return ApiResponse.success(page);
	}
	
	@ApiOperation(value = "鑫合汇已发标统计", response = Boolean.class, httpMethod="POST", tags={"新增"})
    @RequestMapping(value = "countXHHNum", method = RequestMethod.POST)
	public ApiResponse countXHHNum(@ModelAttribute ClientTypeExt clientTypeExt){
		clientTypeExt.notDeleted();
        PageVo page = getPage(clientTypeExt);
        clientTypeExt.setThirdBusiStatus(300);
		int records=ywBusinessService.countXHHNum(clientTypeExt);
		if (records > 0) {
			page.setRecords(records);
            List<BusinessTotalVo> dpBaseDataDictionaries = ywBusinessService.selectXHHNum(clientTypeExt);
            for (BusinessTotalVo dzGpsList : dpBaseDataDictionaries) {
            	dzGpsList.setBusiStatusDisplay(cachedDictionaryService.getName(dzGpsList.getBusiStatus().toString(), DataDicType.BUSI_STATUS));
            	dzGpsList.setThiredStatusDisplay(cachedDictionaryService.getName(dzGpsList.getThiredStatus().toString(), DataDicType.THIRED_STATUS));
			}
            page.setRows(dpBaseDataDictionaries);
        } else {
            page.setRows(CollectionInitUtil.emptyList());
        }
		
		return ApiResponse.success(page);
	}
}
